package com.fix.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.fix.dao.UserDao;
import com.fix.dao.impl.UserDaoImpl;
import com.fix.entity.User;

/**
 * Servlet implementation class Loginservlet
 */
@WebServlet("/login")
public class Loginservlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	UserDao userDao =new UserDaoImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name= request.getParameter("stname");
		String pass=request.getParameter("stpass");
		
		try {
			User user =userDao.login(name,pass);
			if(user==null) {
				response.sendRedirect("login.jsp");
			}else {
				HttpSession session =request.getSession();
		      
				session.setAttribute("user", user);
				
			
				
			    
			    request.getRequestDispatcher("index.jsp").forward(request, response);
			    
			
			}
			
		} catch (Exception e) {
			// TODO: handle exception
		}
			
			
		
		
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
